package cn.jy.map.service.impl;

import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.lang.reflect.Method;
import java.text.NumberFormat;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.UUID;

import javax.annotation.PostConstruct;

import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.util.EntityUtils;
import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import cn.jy.map.domain.AddressJwdMsg;
import cn.jy.map.domain.AddressMsg;
import cn.jy.map.domain.CollectionRecord;
import cn.jy.map.domain.GjzDzJwd;
import cn.jy.map.domain.GjzLc;
import cn.jy.map.domain.JzJyDz;
import cn.jy.map.domain.Nurse;
import cn.jy.map.domain.NurseGjzColligate;
import cn.jy.map.domain.ProviderBaseInfo;
import cn.jy.map.domain.ProviderRegister;
import cn.jy.map.domain.RegisterGtt;
import cn.jy.map.domain.VillageColligate;
import cn.jy.map.domain.Wxjyy;
import cn.jy.map.domain.XyDmRounds;
import cn.jy.map.mapper.GjzAllTypeMapper;
import cn.jy.map.mapper.GjzDzJwdMapper;
import cn.jy.map.mapper.GjzLcMapper;
import cn.jy.map.mapper.GjzxxMapper;
import cn.jy.map.mapper.JzjydzMapper;
import cn.jy.map.mapper.LcblfyMapper;
import cn.jy.map.mapper.RegisterGttMapper;
import cn.jy.map.mapper.VillageColligateMapper;
import cn.jy.map.service.GjzDzJwdService;
import cn.jy.map.service.LoadAllDataService;
import cn.jy.map.service.VillageColligateService;
import cn.jy.map.utils.GjzType;
import cn.jy.map.utils.MapUtils;
import cn.jy.nvr.datasource.DataSourceConst;
import cn.jy.nvr.datasource.DataSourceContextHolder;
import net.sf.json.JSONObject;

@Service("loadDataService")
public class LoadAllDataServiceImpl implements LoadAllDataService {

	@Autowired
	GjzLcMapper gjzLcMapper;
	@Autowired
	GjzxxMapper gjzxxMapper;
	@Autowired
	GjzDzJwdMapper gjzDzJwdMapper;
	@Autowired
	RegisterGttMapper registerGttMapper;
	@Autowired
	GjzAllTypeMapper gjzAllTypeMapper;
	@Autowired
	LcblfyMapper lcblfyMapper;
	@Autowired
	VillageColligateService villageColligateService;
	@Autowired
	VillageColligateMapper villageColligateMapper;

	@Autowired
	private GjzDzJwdService gjzDzJwdService;
	@Autowired
	private JzjydzMapper jzjydzMapper;


	static Logger logger = Logger.getLogger(LoadAllDataServiceImpl.class);
	private JzJyDz jzJyDz;


	@Override
	public void loadRegGjzLcData(String date) {

		DataSourceContextHolder.setDataSourceType(DataSourceConst.jingying);
		List<ProviderRegister> regList = registerGttMapper.getRegisterByDate(date);

		if(regList != null && regList.size()>0){
			logger.info("开始重新装载【"+date+"】登记的供浆者轮次数据~~~");
			for(ProviderRegister preg : regList){

				String providerNo = preg.getProviderNo();
				DataSourceContextHolder.setDataSourceType(DataSourceConst.mx);
				GjzLc gjzLc = gjzLcMapper.getGjzLcByPNo(preg.getProviderNo());

				if(gjzLc == null){
					DataSourceContextHolder.setDataSourceType(DataSourceConst.jingying);
					GjzLc lc = new GjzLc();
					lc.setId(UUID.randomUUID().toString());
					lc.setName(preg.getName());
					lc.setProviderNo(providerNo);
					lc.setSex(preg.getSex());
					lc.setAge(MapUtils.getAge(MapUtils.parseDate(preg.getBirthday())));

					int pulpAge = gjzLcMapper.getpulpAge(providerNo);
					//					if(pulpAge == null || "".equals(pulpAge)){
					//						pulpAge = "0";
					//					}
					lc.setPulpAge(pulpAge);

					Map<String, Object> pulps = gjzLcMapper.getPulps(providerNo);

					lc.setTimes(pulps.get("times") == null ? 0 : (Integer)pulps.get("times"));
					lc.setLastYearPulps(pulps.get("lastYearPulps") == null ? 0 : (Integer)pulps.get("lastYearPulps"));
					lc.setCurrentTimePulps(pulps.get("currentTimePulps") == null ? 0 : (Integer)pulps.get("currentTimePulps"));//今年当期总次数
					String year = MapUtils.getCurrentYear();
					lc.setCurrentYear(Integer.parseInt(year));

					//------------------------------------------------------------------------

					String lastYear = MapUtils.getThatYear(MapUtils.getCurrentYear(), -1);

					String retime = null;
					DataSourceContextHolder.setDataSourceType(DataSourceConst.mx);
					List<XyDmRounds> nowRounds = gjzLcMapper.getXyDmRounds(MapUtils.getNowOnlyDateFomat1());//获取当前时候的轮次
					if(nowRounds != null && nowRounds.size()>0){
						XyDmRounds round = nowRounds.get(0);
						retime = round.getRETIME();

						retime = MapUtils.formatDate1(retime);//当前轮次的最后日期

						retime = MapUtils.getThatDate(retime, -1);

					}else{
						retime = MapUtils.getLastYearNow();
					}


					DataSourceContextHolder.setDataSourceType(DataSourceConst.jingying);
					int lastTimePulps = gjzLcMapper.getPulpsByTime(providerNo, lastYear + "-01-01", retime);//去年同期总次数
					lc.setLastTimePulps(lastTimePulps);


					if(preg.getAddress() != null && !"".equals(preg.getAddress())){
						String address;//详细地址

						List<String> addList = splitAddress(preg.getAddress());
						if(addList != null && addList.size() > 2){
							address = addList.get(addList.size() - 1) + addList.get(addList.size() - 2);
						}else{
							address = preg.getAddress();
						}
						lc.setAddress(address);
					}
					DataSourceContextHolder.setDataSourceType(DataSourceConst.mx);
					Map<String, Object> nurseAndYG = gjzxxMapper.getNurseAndYG(providerNo);
					if(nurseAndYG != null){
						String manageNurseId = (String) nurseAndYG.get("HSXM");//护士管理者姓名
						Long yiGongId = (Long) nurseAndYG.get("YGXM");//义工
						String manageNurse = "";

						if(manageNurseId != null && !"".equals(manageNurseId)){
							manageNurse = gjzxxMapper.getNurseById(manageNurseId);
						}
						if(yiGongId != null && !"".equals(yiGongId)){
							String yg = gjzxxMapper.getProviderNameById(yiGongId);
							lc.setYiGong(yg);
							lc.setYiGongId(yiGongId+"");
						}
						lc.setManageNurse(manageNurse);
						lc.setManageNurseId(manageNurseId);
					}
					//添加最新的未献浆沟通结果
					List<Wxjyy> reason = lcblfyMapper.getGtReason(providerNo);
					if(reason != null && reason.size()>0){
						Wxjyy rm = reason.get(0);
						String wxjyy = rm.getWxjyy();
						lc.setCommunResult(wxjyy);
					}

					//------------------------------------------------------------------------
					setGjzLcData(lc, year, null, providerNo);

					DataSourceContextHolder.setDataSourceType(DataSourceConst.mx);

					gjzLcMapper.saveGjzLc(lc);
					logger.info("添加【"+providerNo+" ： "+preg.getSmallNo()+"】登记的轮次信息成功！！");
				}else{
					DataSourceContextHolder.setDataSourceType(DataSourceConst.jingying);
					Map<String, Object> pulps = gjzLcMapper.getPulps(providerNo);

					gjzLc.setTimes(pulps.get("times") == null ? 0 : (Integer)pulps.get("times"));
					gjzLc.setLastYearPulps(pulps.get("lastYearPulps") == null ? 0 : (Integer)pulps.get("lastYearPulps"));
					gjzLc.setCurrentTimePulps(pulps.get("currentTimePulps") == null ? 0 : (Integer)pulps.get("currentTimePulps"));
					String year = MapUtils.getCurrentYear();
					gjzLc.setCurrentYear(Integer.parseInt(year));


					//------------------------------------------------------------------------

					String lastYear = MapUtils.getThatYear(MapUtils.getCurrentYear(), -1);

					String retime = null;
					DataSourceContextHolder.setDataSourceType(DataSourceConst.mx);
					List<XyDmRounds> nowRounds = gjzLcMapper.getXyDmRounds(MapUtils.getNowOnlyDateFomat1());//获取当前时候的轮次
					if(nowRounds != null && nowRounds.size()>0){
						XyDmRounds round = nowRounds.get(0);
						retime = round.getRETIME();

						retime = MapUtils.formatDate1(retime);//当前轮次的最后日期

						retime = MapUtils.getThatDate(retime, -1);

					}else{
						retime = MapUtils.getLastYearNow();
					}


					DataSourceContextHolder.setDataSourceType(DataSourceConst.jingying);
					int lastTimePulps = gjzLcMapper.getPulpsByTime(providerNo, lastYear + "-01-01", retime);//去年同期总次数
					gjzLc.setLastTimePulps(lastTimePulps);
					DataSourceContextHolder.setDataSourceType(DataSourceConst.mx);
					Map<String, Object> nurseAndYG = gjzxxMapper.getNurseAndYG(providerNo);
					if(nurseAndYG != null){
						String manageNurseId = (String) nurseAndYG.get("HSXM");//护士管理者姓名
						Long yiGongId = (Long) nurseAndYG.get("YGXM");//义工
						String manageNurse = "";

						if(manageNurseId != null && !"".equals(manageNurseId)){
							manageNurse = gjzxxMapper.getNurseById(manageNurseId);
						}
						if(yiGongId != null && !"".equals(yiGongId)){
							String yg = gjzxxMapper.getProviderNameById(yiGongId);
							gjzLc.setYiGong(yg);
							gjzLc.setYiGongId(yiGongId+"");
						}
						gjzLc.setManageNurse(manageNurse);
						gjzLc.setManageNurseId(manageNurseId);
					}

					//------------------------------------------------------------------------

					//添加最新的未献浆沟通结果
					List<Wxjyy> reason = lcblfyMapper.getGtReason(providerNo);
					if(reason != null && reason.size()>0){
						Wxjyy rm = reason.get(0);
						String wxjyy = rm.getWxjyy();
						gjzLc.setCommunResult(wxjyy);
					}

					setGjzLcData(gjzLc, year, date, providerNo);

					DataSourceContextHolder.setDataSourceType(DataSourceConst.mx);

					gjzLcMapper.updateGjzLc(gjzLc);
					logger.info("更新【"+providerNo+" ： "+preg.getSmallNo()+"】登记的轮次信息成功！！");
				}



			}
		}



	}


	@Override
	public void loadGjzDzJwdData(String date) {
		ProviderBaseInfo pbif = new ProviderBaseInfo();
		pbif.setFileDate(date);
		DataSourceContextHolder.setDataSourceType(DataSourceConst.jingying);
		List<ProviderBaseInfo> gjzList = gjzxxMapper.getAllProviderBaseInfo(pbif);

		logger.info("待装载的供浆者经纬度数据的供浆者条数："+gjzList.size());
		if(gjzList != null && gjzList.size()>0){
			logger.info("开始装载供浆者经纬度数据~~~");

			DataSourceContextHolder.setDataSourceType(DataSourceConst.mx);
			for(ProviderBaseInfo baseInfo : gjzList){

				//先看这个人是否已经装载
				GjzDzJwd gjzDzJwd = gjzDzJwdMapper.getGjzJwdByCardNo(baseInfo.getIDNo());

				if(gjzDzJwd != null && !"".equals(gjzDzJwd.getCARDNO())){

					if(!baseInfo.getProviderNo().equals(gjzDzJwd.getPROVIDERNO())){

						gjzDzJwd.setPROVIDERNO(baseInfo.getProviderNo());
						gjzDzJwd.setPROVIDERSTATE(baseInfo.getProviderState());

						gjzDzJwdMapper.updateGjzDzJwd(gjzDzJwd);
					}

					continue;
				}


				String address = baseInfo.getAddress();

				List<String> addList = splitAddress(address);
				//[甘肃省, 岷县, 八郎村]
				getJzJyDzByAddress(null, null, addList);

				GjzDzJwd jwd = new GjzDzJwd();
				jwd.setID(UUID.randomUUID().toString());
				jwd.setPROVIDERNO(baseInfo.getProviderNo());
				jwd.setCARDNO(baseInfo.getIDNo());
				jwd.setNAME(baseInfo.getName());
				jwd.setGENDER(baseInfo.getSex());
				jwd.setBIRTHDAY(baseInfo.getBirthDay());
				jwd.setFILEDATE(baseInfo.getFileDate());
				jwd.setADDRESS(baseInfo.getAddress());
				jwd.setPROVIDERSTATE(baseInfo.getProviderState());
				//如果jzJyDz为null则说明地址经纬度码表里面没有该 地址的信息，最高连省都没有
				if(jzJyDz != null){
					jwd.setNATIVEPLACE(jzJyDz.getPATH().replace(".", ""));
					jwd.setGX(jzJyDz.getGX());
					jwd.setGY(jzJyDz.getGY());
					jwd.setCODE(jzJyDz.getCODE());
				}

				gjzDzJwdMapper.addGjzDzJwd(jwd);

				jzJyDz = null;

				logger.info("装载【"+jwd+"】成功~~");

			}

			logger.info("装载供浆者经纬度数据结束~~~");
		}



	}

	@Override
	public void loadGjzLcData() {

		ProviderBaseInfo pbif = new ProviderBaseInfo();
		DataSourceContextHolder.setDataSourceType(DataSourceConst.jingying);
		List<ProviderBaseInfo> gjzList = gjzxxMapper.getAllProviderBaseInfo(pbif);

		logger.info("待装载的供浆者轮次数据条数："+gjzList.size());
		if(gjzList != null && gjzList.size()>0){
			logger.info("开始装载供浆者轮次数据~~~");


			for(ProviderBaseInfo baseInfo : gjzList){
				String providerNo = baseInfo.getProviderNo();
				DataSourceContextHolder.setDataSourceType(DataSourceConst.mx);

				GjzLc gjzLc = gjzLcMapper.getGjzLcByPNo(providerNo);
				if(gjzLc != null){
					//					if(gjzLc == null){
					//						DataSourceContextHolder.setDataSourceType(DataSourceConst.jingying);
					//						
					//						GjzLc lc = new GjzLc();
					//						lc.setId(UUID.randomUUID().toString());
					//						lc.setName(baseInfo.getName());
					//						lc.setProviderNo(providerNo);
					//						lc.setSex(baseInfo.getSex());
					//						lc.setAge(MapUtils.getAge(MapUtils.parseDate(baseInfo.getBirthDay())));
					//						
					//						int pulpAge = gjzLcMapper.getpulpAge(providerNo);
					////						if(pulpAge == null || "".equals(pulpAge)){
					////							pulpAge = "0";
					////						}
					//						lc.setPulpAge(pulpAge);
					//						
					//						Map<String, Object> pulps = gjzLcMapper.getPulps(providerNo);
					//						
					//						lc.setTimes(pulps.get("times") == null ? 0 : (Integer)pulps.get("times"));
					//						lc.setLastYearPulps(pulps.get("lastYearPulps") == null ? 0 : (Integer)pulps.get("lastYearPulps"));
					//						lc.setCurrentTimePulps(pulps.get("currentTimePulps") == null ? 0 : (Integer)pulps.get("currentTimePulps"));
					//						String year = MapUtils.getCurrentYear();
					//						lc.setCurrentYear(Integer.parseInt(year));
					//						
					//						//------------------------------------------------------------------------
					//
					//						String lastYear = MapUtils.getThatYear(MapUtils.getCurrentYear(), -1);
					//						int lastTimePulps = gjzLcMapper.getPulpsByTime(providerNo, lastYear + "-01-01",MapUtils.getLastYearNow());//去年同期总次数
					//						lc.setLastTimePulps(lastTimePulps);
					//						
					//						
					//						if(baseInfo.getNativePlace() != null && !"".equals(baseInfo.getNativePlace())){
					//							String address;//详细地址
					//							
					//							List<String> addList = this.splitAddress(baseInfo.getNativePlace());
					//							if(addList != null && addList.size() > 2){
					//								address = addList.get(addList.size() - 2) + baseInfo.getNativePlace().substring(baseInfo.getNativePlace().indexOf(addList.get(addList.size() - 1)), baseInfo.getNativePlace().length());//addList.get(addList.size() - 1) + addList.get(addList.size() - 2);
					//							}else{
					//								address = baseInfo.getNativePlace();
					//							}
					//							lc.setAddress(address);
					//						}
					//						DataSourceContextHolder.setDataSourceType(DataSourceConst.mx);
					//						Map<String, Object> nurseAndYG = gjzxxMapper.getNurseAndYG(providerNo);
					//						if(nurseAndYG != null){
					//							String manageNurse = (String) nurseAndYG.get("HSXM");//护士管理者姓名
					//							Long yiGong = (Long) nurseAndYG.get("YGXM");//义工
					//							
					//							if(manageNurse != null && !"".equals(manageNurse)){
					//								manageNurse = gjzxxMapper.getNurseById(manageNurse);
					//							}
					//							if(yiGong != null && !"".equals(yiGong)){
					//								String yg = gjzxxMapper.getProviderNameById(yiGong);
					//								lc.setYiGong(yg);
					//							}
					//							lc.setManageNurse(manageNurse);
					//						}
					//						
					//						
					//						
					//						//------------------------------------------------------------------------
					//						
					//						
					//						
					//						setGjzLcData(lc, year, null, providerNo);
					//						
					//						DataSourceContextHolder.setDataSourceType(DataSourceConst.mx);
					//						
					//						gjzLcMapper.saveGjzLc(lc);
					//						logger.info("添加供浆者【"+providerNo+"】的轮次信息成功！！");
					//					}else{
					DataSourceContextHolder.setDataSourceType(DataSourceConst.jingying);
					Map<String, Object> pulps = gjzLcMapper.getPulps(providerNo);

					gjzLc.setTimes(pulps.get("times") == null ? 0 : (Integer)pulps.get("times"));
					gjzLc.setLastYearPulps(pulps.get("lastYearPulps") == null ? 0 : (Integer)pulps.get("lastYearPulps"));//去年全年现将量
					gjzLc.setCurrentTimePulps(pulps.get("currentTimePulps") == null ? 0 : (Integer)pulps.get("currentTimePulps"));//今年档期现将量
					String year = MapUtils.getCurrentYear();
					gjzLc.setCurrentYear(Integer.parseInt(year));


					//------------------------------------------------------------------------

					String lastYear = MapUtils.getThatYear(MapUtils.getCurrentYear(), -1);

					String retime = null;
					DataSourceContextHolder.setDataSourceType(DataSourceConst.mx);
					List<XyDmRounds> nowRounds = gjzLcMapper.getXyDmRounds(MapUtils.getNowOnlyDateFomat1());//获取当前时候的轮次
					if(nowRounds != null && nowRounds.size()>0){
						XyDmRounds round = nowRounds.get(0);
						retime = round.getRETIME();

						retime = MapUtils.formatDate1(retime);//当前轮次的最后日期

						retime = MapUtils.getThatDate(retime, -1);

					}else{
						retime = MapUtils.getLastYearNow();
					}
					DataSourceContextHolder.setDataSourceType(DataSourceConst.jingying);
					int lastTimePulps = gjzLcMapper.getPulpsByTime(providerNo, lastYear + "-01-01",retime);//去年同期总次数
					gjzLc.setLastTimePulps(lastTimePulps);//去年同期现将量

					DataSourceContextHolder.setDataSourceType(DataSourceConst.mx);
					Map<String, Object> nurseAndYG = gjzxxMapper.getNurseAndYG(providerNo);
					if(nurseAndYG != null){
						String manageNurseId = (String) nurseAndYG.get("HSXM");//护士管理者姓名
						Long yiGongId = (Long) nurseAndYG.get("YGXM");//义工
						String manageNurse = "";

						if(manageNurseId != null && !"".equals(manageNurseId)){
							manageNurse = gjzxxMapper.getNurseById(manageNurseId);
						}
						if(yiGongId != null && !"".equals(yiGongId)){
							String yg = gjzxxMapper.getProviderNameById(yiGongId);
							gjzLc.setYiGong(yg);
							gjzLc.setYiGongId(yiGongId+"");
						}
						gjzLc.setManageNurse(manageNurse);
						gjzLc.setManageNurseId(manageNurseId);
					}



					//------------------------------------------------------------------------

					//添加最新的未献浆沟通结果
					List<Wxjyy> reason = lcblfyMapper.getGtReason(providerNo);
					if(reason != null && reason.size()>0){
						Wxjyy rm = reason.get(0);
						String wxjyy = rm.getWxjyy();
						gjzLc.setCommunResult(wxjyy);
					}

					setGjzLcData(gjzLc, year, null, providerNo);

					DataSourceContextHolder.setDataSourceType(DataSourceConst.mx);

					gjzLcMapper.updateGjzLc(gjzLc);
					logger.info("更新供浆者【"+providerNo+"】的轮次信息成功！！");
					//					}

				}else{

					DataSourceContextHolder.setDataSourceType(DataSourceConst.jingying);


					GjzLc lc = new GjzLc();
					lc.setId(UUID.randomUUID().toString());
					lc.setName(baseInfo.getName());
					lc.setProviderNo(providerNo);
					lc.setSex(baseInfo.getSex());
					lc.setAge(MapUtils.getAge(MapUtils.parseDate(baseInfo.getBirthDay())));

					int pulpAge = gjzLcMapper.getpulpAge(providerNo);//江铃
					//					if(pulpAge == null || "".equals(pulpAge)){
					//						pulpAge = "0";
					//					}
					lc.setPulpAge(pulpAge);

					Map<String, Object> pulps = gjzLcMapper.getPulps(providerNo);

					lc.setTimes(pulps.get("times") == null ? 0 : (Integer)pulps.get("times"));
					lc.setLastYearPulps(pulps.get("lastYearPulps") == null ? 0 : (Integer)pulps.get("lastYearPulps"));
					lc.setCurrentTimePulps(pulps.get("currentTimePulps") == null ? 0 : (Integer)pulps.get("currentTimePulps"));
					String year = MapUtils.getCurrentYear();
					lc.setCurrentYear(Integer.parseInt(year));


					//------------------------------------------------------------------------

					String lastYear = MapUtils.getThatYear(MapUtils.getCurrentYear(), -1);

					String retime = null;
					DataSourceContextHolder.setDataSourceType(DataSourceConst.mx);
					List<XyDmRounds> nowRounds = gjzLcMapper.getXyDmRounds(MapUtils.getNowOnlyDateFomat1());//获取当前时候的轮次
					if(nowRounds != null && nowRounds.size()>0){
						XyDmRounds round = nowRounds.get(0);
						retime = round.getRETIME();

						retime = MapUtils.formatDate1(retime);//当前轮次的最后日期

						retime = MapUtils.getThatDate(retime, -1);

					}else{
						retime = MapUtils.getLastYearNow();
					}


					DataSourceContextHolder.setDataSourceType(DataSourceConst.jingying);
					int lastTimePulps = gjzLcMapper.getPulpsByTime(providerNo, lastYear + "-01-01",retime);//去年同期总次数
					lc.setLastTimePulps(lastTimePulps);


					if(baseInfo.getNativePlace() != null && !"".equals(baseInfo.getNativePlace())){
						String address;//详细地址

						List<String> addList = splitAddress(baseInfo.getNativePlace());
						if(addList != null && addList.size() > 2){
							address = addList.get(addList.size() - 2) + baseInfo.getNativePlace().substring(baseInfo.getNativePlace().indexOf(addList.get(addList.size() - 1)), baseInfo.getNativePlace().length());
						}else{
							address = baseInfo.getNativePlace();
						}
						lc.setAddress(address);
					}
					DataSourceContextHolder.setDataSourceType(DataSourceConst.mx);
					Map<String, Object> nurseAndYG = gjzxxMapper.getNurseAndYG(providerNo);
					if(nurseAndYG != null){
						String manageNurseId = (String) nurseAndYG.get("HSXM");//护士管理者姓名
						Long yiGongId = (Long) nurseAndYG.get("YGXM");//义工
						String manageNurse = "";

						if(manageNurseId != null && !"".equals(manageNurseId)){
							manageNurse = gjzxxMapper.getNurseById(manageNurseId);
						}
						if(yiGongId != null && !"".equals(yiGongId)){
							String yg = gjzxxMapper.getProviderNameById(yiGongId);
							lc.setYiGong(yg);
							lc.setYiGongId(yiGongId+"");
						}
						lc.setManageNurse(manageNurse);
						lc.setManageNurseId(manageNurseId);
					}

					//添加最新的未献浆沟通结果
					List<Wxjyy> reason = lcblfyMapper.getGtReason(providerNo);
					if(reason != null && reason.size()>0){
						Wxjyy rm = reason.get(0);
						String wxjyy = rm.getWxjyy();
						lc.setCommunResult(wxjyy);
					}

					//------------------------------------------------------------------------


					setGjzLcData(lc, year, null, providerNo);

					DataSourceContextHolder.setDataSourceType(DataSourceConst.mx);

					gjzLcMapper.saveGjzLc(lc);
					logger.info("添加供浆者【"+providerNo+"】的轮次信息成功！！");
				}


			}

		}

	}

	private void setGjzLcData(GjzLc lc,String year,String date,String providerNo){

		// 将所有未献浆的设置为 “0”
		for(int i=1;i<27;i++){
			this.setCurrentHasNullLc(lc, i+"");
			this.setLastHasNullLc(lc, i+"");
		}

		DataSourceContextHolder.setDataSourceType(DataSourceConst.jingying);
		List<CollectionRecord> recordList = gjzLcMapper.getCollectionRecord(year, date, providerNo);

		if(recordList != null && recordList.size() > 0){
			for(CollectionRecord coll : recordList){
				String collectionDate = coll.getCollectionDate();
				DataSourceContextHolder.setDataSourceType(DataSourceConst.mx);
				collectionDate = MapUtils.formatDate1(collectionDate);
				List<XyDmRounds> xyDmRounds = gjzLcMapper.getXyDmRounds(collectionDate);

				XyDmRounds xyDmRound = null;
				if(xyDmRounds != null && xyDmRounds.size()>0){
					xyDmRound = xyDmRounds.get(0);

					String rid = xyDmRound.getRID();

					setGjzLcRounds(rid, lc,"1:"+collectionDate);

				}
			}
		}

		DataSourceContextHolder.setDataSourceType(DataSourceConst.jingying);
		List<CollectionRecord> lastRecordList = gjzLcMapper.getCollectionRecord(MapUtils.getThatYear(year, -1), date, providerNo);

		if(lastRecordList != null && lastRecordList.size() > 0){
			for(CollectionRecord coll : lastRecordList){
				String collectionDate = coll.getCollectionDate();
				collectionDate = MapUtils.formatDate1(collectionDate);
				String cd = MapUtils.getCurrentYear() + collectionDate.substring(4, collectionDate.length());
				DataSourceContextHolder.setDataSourceType(DataSourceConst.mx);
				List<XyDmRounds> xyDmRounds = gjzLcMapper.getXyDmRounds(cd);

				XyDmRounds xyDmRound = null;
				if(xyDmRounds != null && xyDmRounds.size()>0){
					xyDmRound = xyDmRounds.get(0);

					String rid = xyDmRound.getRID();
					setGjzLcLastYearRounds(rid, lc,"1:"+collectionDate);

				}
			}
		}


		//获取这个浆员的临床反应记录
		DataSourceContextHolder.setDataSourceType(DataSourceConst.mx);
		List<String> list = lcblfyMapper.getBlfyDateByProviderNo(providerNo);
		if(list != null){
			for (String rq : list) {

				int isCurrentYear = -1;

				if(rq.startsWith(MapUtils.getThatYear(MapUtils.getCurrentYear(), -1))){
					//去年的临床反应
					isCurrentYear = 1;
				}else if(rq.startsWith(MapUtils.getCurrentYear())){
					isCurrentYear = 2;
				}
				DataSourceContextHolder.setDataSourceType(DataSourceConst.mx);
				List<XyDmRounds> xyDmRounds = gjzLcMapper.getXyDmRounds(rq);

				XyDmRounds xyDmRound = null;
				if(xyDmRounds != null && xyDmRounds.size()>0){
					xyDmRound = xyDmRounds.get(0);

					String rid = xyDmRound.getRID();
					if(isCurrentYear == 2){
						setGjzLcRounds(rid, lc,"2:"+rq);
					}else if(isCurrentYear == 1){
						setGjzLcLastYearRounds(rid, lc,"2:"+rq);
					}

				}

			}
		}


	}

	private void setCurrentHasNullLc(GjzLc gjzLc,String lc){
		try {
			Class<?> clazz = Class.forName("cn.jy.map.domain.GjzLc");

			Method setRound = clazz.getMethod("setRound"+lc, String.class);
			setRound.invoke(gjzLc, "0");


		} catch (Exception e) {
			e.printStackTrace();
		}
	}
	private void setLastHasNullLc(GjzLc gjzLc,String lc){
		try {
			Class<?> clazz = Class.forName("cn.jy.map.domain.GjzLc");

			Method setRound = clazz.getMethod("setLastRound"+lc, String.class);
			setRound.invoke(gjzLc, "0");



		} catch (Exception e) {
			e.printStackTrace();
		}
	}

	private void setGjzLcRounds(String rid,GjzLc gjzLc,String value){
		try {
			Class<?> clazz = Class.forName("cn.jy.map.domain.GjzLc");

			Method setRound = clazz.getMethod("setRound"+rid, String.class);

			setRound.invoke(gjzLc, value);


		} catch (Exception e) {
			e.printStackTrace();
		}
	}
	private void setGjzLcLastYearRounds(String rid,GjzLc gjzLc,String value){
		try {
			Class<?> clazz = Class.forName("cn.jy.map.domain.GjzLc");

			Method setRound = clazz.getMethod("setLastRound"+rid, String.class);

			setRound.invoke(gjzLc, value);


		} catch (Exception e) {
			e.printStackTrace();
		}
	}


	@Override
	public void loadGjzRegGtt(String date) {
		DataSourceContextHolder.setDataSourceType(DataSourceConst.mx);
		List<RegisterGtt> regs = registerGttMapper.getJiayingReg(date);

		logger.info("待装载的供浆者登记甘特图条数："+regs.size());

		if(regs != null && regs.size()>0){
			for(RegisterGtt reg : regs){

				if(reg.getCREATEDATE() == null || "".equals(reg.getCREATEDATE())){
					continue;
				}

				String createdate = MapUtils.formatDate1(reg.getCREATEDATE());
				String regdate = MapUtils.formatDate1(reg.getSTARTTIME());

				reg.setCREATEDATE(createdate);
				String regTime = reg.getSTARTTIME();
				if(regTime.length() > 19){
					reg.setSTARTTIME(regTime.substring(0, 19));
				}

				if(createdate.equals(regdate)){
					reg.setISNEW("1");
				}else{
					reg.setISNEW("0");
				}
				if(reg.getENDTIME() == null || "".equals(reg.getENDTIME())){
					String now = MapUtils.getNowOnlyDateFomat1();
					reg.setIsEnd("0");
					if(regdate.equals(now)){
						reg.setENDTIME(MapUtils.getNow());
					}else{
						reg.setENDTIME(MapUtils.getDateHour(regdate, "18", "00"));//如果根本没有结束时间，就默认成当天的下午18点
					}
				}else{
					reg.setIsEnd("1");
				}


				List<RegisterGtt> reggList = registerGttMapper.getRegGttBySmallNo(reg.getSMALLNO(), reg.getSFZ());
				if(reggList != null && reggList.size()>0){
					RegisterGtt registerGtt = reggList.get(0);
					reg.setID(registerGtt.getID());

					registerGttMapper.updateRegGtt(reg);
				}else{
					registerGttMapper.saveRegGtt(reg);
				}


				logger.info("装载供浆者登记【"+reg.getSMALLNO()+"】甘特图成功~~~");
			}
		}

	}


	private void getJzJyDzByAddress(String path,String name,List<String> addList){

		if(addList != null && addList.size()>0){
			if(path == null && name == null){
				//证明是第一次传进来
				path = "%";
				for(String address : addList){
					path += address+"%";
				}
				name = addList.get(addList.size()-1);
			}

			List<JzJyDz> dzList = gjzxxMapper.getJzJyDzByAddress(path, name);

			if(dzList.size() == 0){
				addList.remove(addList.size() - 1);
				path = "%";
				for(String address : addList){
					path += address+"%";
				}
				if(addList.size()>0){
					name = addList.get(addList.size()-1);
				}
				getJzJyDzByAddress(path, name, addList);
			}else{
				jzJyDz = dzList.get(0);
			}
		}

	}

	public static void main(String[] args) {
		//		else{
		//			//没有以村结束的，比如：甘肃省定西地区岷县岷阳镇二渠河180号
		//			if(zhen > 0 ){
		//				cun_ = address.substring(zhen + 1);
		//			}
		//		}
		//		String address ="甘肃省定西地区";
		//		String address ="甘肃省甘南藏族自治州迭部县";
		//		String address ="甘肃省宕昌县城关镇坡头村";
		//		String address ="甘肃省定西地区岷县岷阳镇二渠河178号";
		//		String address ="甘肃省定西地区岷县岷阳镇教场街";
		//		String address ="甘肃省定西地区岷县禾驮乡卓洛沟141号";
		//		String address ="甘肃省岷县岷阳镇简营家属院49号";
		//		String address ="甘肃省岷县茶埠镇高岸树73号";
		//		String address ="甘肃省定西市通川区岷县麻子川乡安山村";
		//		String address ="甘肃省宕昌县哈达铺镇下街";
		//		String address ="甘肃省宕昌县城关镇长征路1排50号";
		//		String address="甘肃省宕昌县哈达铺镇下街";
		//		String address="甘肃省甘南藏族自治州合作市";
		//		String address="甘肃省岷县岷阳镇洮珠村";
		String address="甘肃省定西市岷县十里镇十里乡张家湾村";
		//	    System.out.println(splitAddress(address));
		//		System.out.println(splitAddress(address).size());
		System.out.println(getjwd(address));;
	}

	private static List<String> splitAddress(String address){
		int sheng = address.indexOf("省");
		int shi = address.indexOf("市");
		int diqu = address.indexOf("地区");
		int zzz = address.indexOf("自治州");
		int xian = address.indexOf("县");
		int zhen = address.indexOf("镇");
		int xiang = address.indexOf("乡");
		int cun = address.indexOf("村");
		int jie = address.indexOf("街");
		int xiangzi = address.indexOf("巷");
		int qu=address.indexOf("区");

		String sheng_ = "";
		String diqu_ = "";
		String zzz_ = "";
		String shi_ = "";
		String xian_ = "";
		String zhen_ = "";
		String xiang_ = "";
		String cun_ = "";
		String jie_ = "";
		String xiangzi_ = "";
		String qu_="";
		String other="";

		try {
			if(cun > 0){
				//有村，就用乡/镇来截取是什么村
				if(xiang > 0){
					cun_ = address.substring(xiang + 1, cun + 1);
				}else if(zhen > 0 ){
					cun_ = address.substring(zhen + 1, cun + 1);
				}else if(xian > 0){
					cun_ = address.substring(xian + 1, cun + 1);
				}else if(qu > 0){
					cun_ = address.substring(qu + 1, cun + 1);
				}else if(shi > 0){
					cun_ = address.substring(shi + 1, cun + 1);
				}else if(sheng > 0){
					cun_ = address.substring(sheng + 1, cun + 1);
				}
			}
		} catch (Exception e) {
			logger.error("截取地址【"+address+"】时出错："+e);
		}
		try {
			if(jie > 0){
				if(xiang > 0){
					jie_ = address.substring(xiang + 1, jie + 1);
				}else if(zhen > 0 ){
					jie_ = address.substring(zhen + 1, jie + 1);
				}else if(xian > 0){
					jie_ = address.substring(xian + 1, jie + 1);
				}else if(qu > 0){
					jie_ = address.substring(qu+ 1, jie + 1);
				}else if(shi > 0){
					jie_ = address.substring(shi + 1, jie + 1);
				}else if(sheng > 0){
					jie_ = address.substring(sheng + 1, jie + 1);
				}
			}
		} catch (Exception e) {
			logger.error("截取地址【"+address+"】时出错："+e);
		}

		try {
			if(xiangzi > 0){
				if(zhen > 0 ){
					xiangzi_ = address.substring(zhen + 1, xiangzi + 1);
				}else if(xiang > 0){
					xiangzi_ = address.substring(xiang + 1, xiangzi + 1);
				}else if(xian > 0){
					xiangzi_ = address.substring(xian + 1, xiangzi + 1);
				}else if(qu> 0){
					xiangzi_ = address.substring(qu + 1, xiangzi + 1);
				}else if(shi > 0){
					xiangzi_ = address.substring(shi + 1, xiangzi + 1);
				}else if(sheng > 0){
					xiangzi_ = address.substring(sheng + 1, xiangzi + 1);
				}
			}
		} catch (Exception e) {
			logger.error("截取地址【"+address+"】时出错："+e);
		}
		try {
			if(xiang > 0){
				if(zhen>0){
					xiang_ = address.substring(zhen + 1, xiang + 1);
				}else if(xian > 0){
					xiang_ = address.substring(xian + 1, xiang + 1);
				}else if(qu> 0){
					xiang_ = address.substring(qu+1, xiang + 1);
				}else if(shi > 0){
					xiang_ = address.substring(shi + 1, xiang + 1);
				}else if(sheng > 0){
					xiang_ = address.substring(sheng + 1, xiang + 1);
				}
			}
		} catch (Exception e) {
			logger.error("截取地址【"+address+"】时出错："+e);
		}
		try {
			if(zhen > 0){
				String zhen_1 = "";
				if(diqu >0){
					zhen_1 = address.substring(diqu + 2, zhen + 1);
				}

				if(xian > 0){
					zhen_ = address.substring(xian + 1, zhen + 1);
				}else if(shi > 0){
					zhen_ = address.substring(shi + 1, zhen + 1);
				}else if(sheng > 0){
					zhen_ = address.substring(sheng + 1, zhen + 1);
				}
				if(zhen_1.length()>0){
					if(zhen_.length() > zhen_1.length()){
						zhen_ = zhen_1;
					}
				}
			}
		} catch (Exception e) {
			logger.error("截取地址【"+address+"】时出错："+e);
		}
		try {
			if(xian > 0){
				if(qu>0){
					xian_ = address.substring(qu+ 1, xian + 1);
				}else if(shi > 0){
					xian_ = address.substring(shi + 1, xian + 1);
				}else if(diqu > 0){
					xian_ = address.substring(diqu + 2, xian + 1);
				}else if(zzz > 0){
					xian_ = address.substring(zzz + 3, xian + 1);
				}
				else if(sheng > 0){
					xian_ = address.substring(sheng + 1, xian + 1);
				}

				if(xian_.length() < 1){
					if(sheng > 0){
						xian_ = address.substring(sheng + 1, xian + 1);
					}
				}

			}
		} catch (Exception e) {
			logger.error("截取地址【"+address+"】时出错："+e);
			if(xian_.length() < 1){
				if(sheng > 0){
					xian_ = address.substring(sheng + 1, xian + 1);
				}
			}
		}
		try {
			if(qu > 0){
				if(shi > 0){
					qu_ = address.substring(shi + 1, qu + 1);
				}
			}
		} catch (Exception e) {
			logger.error("截取地址【"+address+"】时出错："+e);
		}
		try {
			if(shi > 0){
				if(sheng > 0){
					shi_ = address.substring(sheng + 1, shi + 1);
				}
			}
		} catch (Exception e) {
			logger.error("截取地址【"+address+"】时出错："+e);
		}
		try {
			if(diqu > 0){
				if(sheng > 0){
					diqu_ = address.substring(sheng + 1, diqu) + "市";

					int dx = diqu_.indexOf("县");
					if(dx > 0){
						diqu_ = diqu_.substring(dx + 1, diqu_.length());
					}

				}
			}
		} catch (Exception e) {
			logger.error("截取地址【"+address+"】时出错："+e);
		}
		try {
			if(zzz > 0){
				if(sheng > 0){
					zzz_ = address.substring(sheng + 1, zzz + 3);
				}
			}
		} catch (Exception e) {
			logger.error("截取地址【"+address+"】时出错："+e);
		}
		try {
			if(sheng > 0){
				sheng_ = address.substring(0, sheng + 1);
			}
		} catch (Exception e) {
			logger.error("截取地址【"+address+"】时出错："+e);
		}
		//处理其他情况，比如：
		List<String> addList = new ArrayList<String>();
		if(!"".equals(sheng_)){
			addList.add(addList.size(), sheng_.trim());
		}
		if(!"".equals(shi_)){
			addList.add(addList.size(), shi_.trim());
		}
		if(!"".equals(diqu_)){
			addList.add(addList.size(), diqu_.trim());
		}
		if(!"".equals(zzz_)){
			addList.add(addList.size(), zzz_.trim());
		}
		if(!"".equals(qu_)){
			addList.add(addList.size(), qu_.trim());
		}
		if(!"".equals(xian_)){
			addList.add(addList.size(), xian_.trim());
		}
		if(!"".equals(zhen_)){
			addList.add(addList.size(), zhen_.trim());
		}
		if(!"".equals(xiang_)){
			addList.add(addList.size(), xiang_.trim());
		}
		if(!"".equals(cun_)){
			addList.add(addList.size(), cun_.trim());
		}
		if(!"".equals(jie_)){
			addList.add(addList.size(), jie_.trim());
		}
		if(!"".equals(xiangzi_)){
			addList.add(addList.size(), xiangzi_.trim());
		}
		
		return addList;
	}

	@PostConstruct()
	private void loadAllData(){
//		this.loadVillageColl(); //完成统计每个村的统计信息，不含经纬度信息 
//		this.loadForgeProvider();  //返回所有废弃浆员的卡号拼成的String
//		this.loadGjzTypeData();      //完成了统计每个浆员类型下面的所有浆员的卡号
//		this.loadVillageJwd();    //   初始化所有村落的地址经纬度综合信息
//		this.loadAllVillProviders(); //装载所有地址下面的所有浆员卡号集合【没有除开废弃浆员和超龄浆员】	
	}



	@Override
	public void loadGjzTypeData(){
		logger.info("初始化所有类型的浆员列表。。。。。。。");
		Map<GjzType, List<String>> allTypeGjzMap = MapUtils.allTypeGjzMap;

		//得到指定日期的年份
		String date = MapUtils.getNowOnlyDateFomat1();
		String thisYear = MapUtils.getThatYear(date);
		//获取指定日期的上一年的年份
		String lastYear = MapUtils.getThatYear(thisYear,-1);//指定日期的当前年份的上一年
		DataSourceContextHolder.setDataSourceType(DataSourceConst.jingying);

		for(int i=0;i<=10;i++){
			List<String> list = null;
			switch (i) {
			case 0:
				DataSourceContextHolder.setDataSourceType(DataSourceConst.jingying);
				list = gjzAllTypeMapper.getAllJy(date);//所有浆员
				if(list == null){
					list = new ArrayList<String>();
				}
				//所有浆员中，除开废弃浆员
				list = MapUtils.removeList(list, MapUtils.allForgeProviderNo);
				allTypeGjzMap.put(GjzType.allGjz, list);
				break;
			case 1:
				DataSourceContextHolder.setDataSourceType(DataSourceConst.jingying);
				list = gjzAllTypeMapper.getThisYearComed(date,thisYear,"1");//今年进站的人
				if(list == null){
					list = new ArrayList<String>();
				}else{
					list = MapUtils.removeList(list, MapUtils.allForgeProviderNo);
				}
				allTypeGjzMap.put(GjzType.thisYearComed, list);
				break;
			case 2:
				DataSourceContextHolder.setDataSourceType(DataSourceConst.jingying);
				list = gjzAllTypeMapper.getNewJy(date, thisYear, lastYear);
				if(list == null){
					list = new ArrayList<String>();
				}else{
					list = MapUtils.removeList(list, MapUtils.allForgeProviderNo);
				}
				allTypeGjzMap.put(GjzType.thisYearCreated, list);//今年新建档的
				break;	
			case 3:
				DataSourceContextHolder.setDataSourceType(DataSourceConst.jingying);
				list = gjzAllTypeMapper.getZcJy(date, thisYear, lastYear);
				if(list == null){
					list = new ArrayList<String>();
				}else{
					list = MapUtils.removeList(list, MapUtils.allForgeProviderNo);
				}
				allTypeGjzMap.put(GjzType.zhongChengGjz, list);
				break;
			case 4:
				DataSourceContextHolder.setDataSourceType(DataSourceConst.jingying);
				list = gjzAllTypeMapper.getfsJy(date, thisYear, lastYear);
				if(list == null){
					list = new ArrayList<String>();
				}else{
					list = MapUtils.removeList(list, MapUtils.allForgeProviderNo);
				}
				allTypeGjzMap.put(GjzType.fuSuGjz, list);
				break;
			case 5:
				DataSourceContextHolder.setDataSourceType(DataSourceConst.mx);
				//获取进站浆员里面的未链接
				List<String> comedList = allTypeGjzMap.get(GjzType.thisYearComed);
				if(comedList.size() > 2000){
					list = new ArrayList<String>();
					int num = comedList.size() / 2000 + 1;
					for(int j=0;j < num;j++){
						int toIndex = 2000 * j + 2000;
						if(toIndex > comedList.size()){
							toIndex = comedList.size();
						}
						List<String> subList = comedList.subList(2000 * j, toIndex);

						List<String> tempList = gjzAllTypeMapper.getLjJy(null,subList);
						list.addAll(tempList);
					}

				}else{
					list = gjzAllTypeMapper.getLjJy(null,comedList);
				}

				if(list == null){
					list = new ArrayList<String>();
				}else{
					list = MapUtils.removeList(list, MapUtils.allForgeProviderNo);
				}
				allTypeGjzMap.put(GjzType.notConnect, list);
				break;	




			case 6:
				//					DataSourceContextHolder.setDataSourceType(DataSourceConst.jingying);
				List<String> list2 = allTypeGjzMap.get(GjzType.allGjz);
				list = MapUtils.removeList(list2, allTypeGjzMap.get(GjzType.thisYearComed));
				//					
				//					list = gjzAllTypeMapper.getThisYearComed(date,thisYear,null);//今年未进站的人
				if(list == null){
					list = new ArrayList<String>();
				}
				//除开废弃浆员
				//					list = MapUtils.removeList(list, MapUtils.allForgeProviderNo);
				allTypeGjzMap.put(GjzType.thisYearNotComed, list);
				break;
			case 7:
				DataSourceContextHolder.setDataSourceType(DataSourceConst.jingying);
				list = gjzAllTypeMapper.getXmJy(date, thisYear, lastYear);
				if(list == null){
					list = new ArrayList<String>();
				}else{
					list = MapUtils.removeList(list, MapUtils.allForgeProviderNo);
				}
				allTypeGjzMap.put(GjzType.xiuMianGjz, list);
				break;
			case 8:
				DataSourceContextHolder.setDataSourceType(DataSourceConst.jingying);
				list = gjzAllTypeMapper.getLsJy(date, thisYear, lastYear);
				if(list == null){
					list = new ArrayList<String>();
				}
				//除开废弃浆员
				list = MapUtils.removeList(list, MapUtils.allForgeProviderNo);
				allTypeGjzMap.put(GjzType.liuShiGjz, list);
				break;
			case 9:
				DataSourceContextHolder.setDataSourceType(DataSourceConst.mx);
				//获取未进站浆员里面的已链接
				List<String> notComedList = allTypeGjzMap.get(GjzType.xiuMianGjz);
				if(notComedList.size() > 2000){
					list = new ArrayList<String>();
					int num = notComedList.size() / 2000 + 1;
					for(int j=0;j < num;j++){
						int toIndex = 2000 * j + 2000;
						if(toIndex > notComedList.size()){
							toIndex = notComedList.size();
						}
						List<String> subList = notComedList.subList(2000 * j, toIndex);

						List<String> tempList = gjzAllTypeMapper.getLjJy("1",subList);
						list.addAll(tempList);
					}

				}else{
					list = gjzAllTypeMapper.getLjJy("1",notComedList);
				}
				if(list == null){
					list = new ArrayList<String>();
				}else{
					list = MapUtils.removeList(list, MapUtils.allForgeProviderNo);
				}
				allTypeGjzMap.put(GjzType.xiuMianBeConnect, list);
				break;

			case 10:
				DataSourceContextHolder.setDataSourceType(DataSourceConst.mx);
				//获取未进站浆员里面的已链接
				List<String> xiuMianList = allTypeGjzMap.get(GjzType.xiuMianGjz);
				//					if(xiuMianList.size() > 2000){
				//						list = new ArrayList<String>();
				//						int num = xiuMianList.size() / 2000 + 1;
				//						for(int j=0;j < num;j++){
				//							int toIndex = 2000 * j + 2000;
				//							if(toIndex > xiuMianList.size()){
				//								toIndex = xiuMianList.size();
				//							}
				//							List<String> subList = xiuMianList.subList(2000 * j, toIndex);
				//							
				//							List<String> tempList = gjzAllTypeMapper.getLjJy(null,subList);
				//							list.addAll(tempList);
				//						}
				//						
				//					}else{
				//						list = gjzAllTypeMapper.getLjJy(null,xiuMianList);
				//					}
				List<String> xiuMianConnList = allTypeGjzMap.get(GjzType.xiuMianBeConnect);
				list = new ArrayList<String>();

				for(String xiumian : xiuMianList){
					boolean flag = true;
					for(String xiumianConn : xiuMianConnList){
						if(xiumian.equals(xiumianConn)){
							flag = false;
							break;
						}
					}
					if(flag){
						list.add(xiumian);
					}

				}
				allTypeGjzMap.put(GjzType.xiuMianNotConnect, list);
				break;

			default:
				break;
			}




		}

		logger.info("初始化所有类型的浆员列表结束。。。。。。。");

		logger.info("初始化所有类型的浆员地址经纬度定位列表。。。。。。。");

		//1：忠诚浆员，2：服务浆员，3：今年新浆员，4：休眠浆员，5：流失浆员，6：链接浆员，7：未链接浆员，8：今年进站的浆员，9：今年未进站的浆员
		Map<String, List<AddressMsg>> allGjzJwdMap = MapUtils.allGjzJwdMap;
		for(int i=0;i<=10;i++){
			List<AddressMsg> list = gjzDzJwdService.getAllGjzDzJwdBySituation(i, date);
			allGjzJwdMap.put("gjzType"+i, list);
		}

		logger.info("初始化所有类型的浆员的地址经纬度定位列表结束。。。。。。。");
	}

	@Override
	public void loadForgeProvider() {
		logger.info("初始化所有2014-10-01前建档但是后面一直没有来的浆员列表。。。。。。。");
		DataSourceContextHolder.setDataSourceType(DataSourceConst.jingying);
		MapUtils.allForgeProviderNo = gjzxxMapper.getAllForgeProviderNo();

		logger.info("初始化所有2014-10-01前建档但是后面一直没有来的浆员列表【"+MapUtils.allForgeProviderNo.size()+"】条！！！");
		//获取去年超龄了的
		String year = MapUtils.getThatYear(MapUtils.getCurrentYear(), -55);
		List<String> tl = gjzxxMapper.getClProviderNo(year);
		logger.info("获取去年超龄了的浆员，就是【"+year+"】年前出生的浆员【"+tl.size()+"】条，放到废弃浆员一堆");

		MapUtils.allForgeProviderNo.addAll(tl);

		MapUtils.allForgeProviderNo = new ArrayList<String>(new HashSet<String>(MapUtils.allForgeProviderNo)); 

		List<String> list = MapUtils.allForgeProviderNo;
		String listStr = "";
		for(String str : list){
			listStr += "'"+str+"',";
		}
		MapUtils.allForgeProviderNoStr = listStr.substring(0, listStr.length()-1);

		logger.info("初始化所有2014-10-01前建档但是后面一直没有来的浆员列表完毕，条数【"+MapUtils.allForgeProviderNo.size()+"】。。。。。。。");

	}

	@Override
	public void loadVillageColl() {
		logger.info("初始化所有村落综合信息。。。。。。。");

		List<VillageColligate> list = villageColligateService.getVillageColligateMsg(null);
		if(list != null){
			for(VillageColligate vill : list){
				MapUtils.allVillageColligate.put(vill.getVillageName(),vill);
			}
		}

		logger.info("初始化所有村落综合信息 结束。。。。。。。");

	}

	@Override
	public void loadVillageJwd() {
		logger.info("初始化所有村落的地址经纬度综合信息。。。。。。。");
		DataSourceContextHolder.setDataSourceType(DataSourceConst.mx);
		List<AddressJwdMsg> list  = gjzDzJwdMapper.getAddressJwdMsg(null,MapUtils.allForgeProviderNoStr);
		if(list != null){
			for(AddressJwdMsg ajm : list){
				List<String> value = new ArrayList<String>();
				value.add(ajm.getJd());
				value.add(ajm.getWd());
				value.add(ajm.getCount()+"");

				AddressMsg am = new AddressMsg();
				am.setName(ajm.getName());
				am.setValue(value);
				am.setVillageColligate(MapUtils.allVillageColligate.get(ajm.getName()));

				MapUtils.allDzJwd.put(ajm.getName(), am);
			}
		}

		logger.info("初始化所有村的地址经纬度综合信息 结束。。。。。。。");

	}


	@Override
	public List<NurseGjzColligate> loadAllNurseProviderLc() {
		logger.info("装载所有护士下面链接的浆员的综合统计信息到数据库。。。。。。。");
		//查询所有护士
		List<Nurse> nurseList = lcblfyMapper.getNurse();
		List<NurseGjzColligate> nurseGjzGoll=null;
		if(nurseList != null){
			for (Nurse nurse : nurseList) {
				logger.info("装载护士【"+nurse.getNurseId()+"】的综合统计信息。。。。。。。");
				DataSourceContextHolder.setDataSourceType(DataSourceConst.mx);
				List<String> allProvider = lcblfyMapper.getNurseConnProvider(nurse.getNurseId(),MapUtils.getThatYear(MapUtils.getCurrentYear(), -56));				
				if(allProvider != null && allProvider.size()>0 ){}else{
					continue;
				}
				NurseGjzColligate ngc = new NurseGjzColligate();

				ngc.setNurseId(nurse.getNurseId());
				ngc.setNurseName(nurse.getNurseName());
				ngc.setAllProviderNum(allProvider.size());

				int lastYearCollNum = 0;//去年献浆总量/袋
				int currentTimePNum = 0;//当期进站人数
				int currentTimeCollNum = 0;//当期献浆量/袋	
				int lastTimePNum = 0;//同期进站人数	
				int lastTimeCollNum = 0;//同期献浆量/袋	
				int currentTimeAddPNum = 0;//当期新增人数	
				int currentTimeAddCollNum = 0;//当期新增总浆量/袋	
				int lastTimeAddPNum = 0;//同期新增人数	
				int lastTimeAddCollNum = 0;//同期新增总浆量/袋	

				DataSourceContextHolder.setDataSourceType(DataSourceConst.jingying);
				StringBuilder allUser=new StringBuilder();
				for (String string : allProvider) {
					allUser.append("'"+string+"'"+",");
				}
				lastYearCollNum = villageColligateMapper.getCollNumsByProviders(MapUtils.getThatYear(MapUtils.getCurrentYear(), -1) + "-01-01", MapUtils.getThatYear(MapUtils.getCurrentYear(), -1) + "-12-31", allProvider);
				//当期进站人数 、当期献浆量/袋	
				Map<String, Integer> tempMap = villageColligateMapper.getcurrentTimeNum(MapUtils.getCurrentYear(),MapUtils.getNowOnlyDateFomat1(), allProvider);
				//Map<String, Integer> tempMap
				currentTimePNum = tempMap.get("NUM");
				currentTimeCollNum= tempMap.get("SUMNUM");
			
				//同期进站人数 、当期献浆量/袋	
				tempMap = villageColligateMapper.getcurrentTimeNum(MapUtils.getThatYear(MapUtils.getCurrentYear(), -1),MapUtils.getLastYearNow(), allProvider);
				lastTimePNum = tempMap.get("NUM");
				
				lastTimeCollNum= tempMap.get("SUMNUM");

				//当期新增人数、当期新增总浆量/袋	
				tempMap = villageColligateMapper.getcurrentTimeAddNum(MapUtils.getCurrentYear(),MapUtils.getNowOnlyDateFomat1(),allProvider);
//				currentTimeAddPNum = tempMap.get("NUM");
				currentTimeAddCollNum = tempMap.get("SUMNUM");
				currentTimeAddPNum=villageColligateMapper.getByNurseProvider(allUser.toString().substring(0, allUser.length()-1));
				//同期新增人数 、当期献浆量/袋	
				tempMap = villageColligateMapper.getcurrentTimeAddNum(MapUtils.getThatYear(MapUtils.getCurrentYear(), -1),MapUtils.getLastYearNow(),allProvider);
				lastTimeAddPNum = tempMap.get("NUM");
				lastTimeAddCollNum = tempMap.get("SUMNUM");
				

				ngc.setLastYearCollNum(lastYearCollNum);

				ngc.setCurrentTimePNum(currentTimePNum);
				ngc.setCurrentTimeCollNum(currentTimeCollNum);
				ngc.setLastTimePNum(lastTimePNum);
				ngc.setLastTimeCollNum(lastTimeCollNum);

				ngc.setCurrentTimeAddPNum(currentTimeAddPNum);
				ngc.setCurrentTimeAddCollNum(currentTimeAddCollNum);
				ngc.setLastTimeAddPNum(lastTimeAddPNum);
				ngc.setLastTimeAddCollNum(lastTimeAddCollNum);


				
				List<String> fsProvider = MapUtils.retainList(allProvider, MapUtils.allTypeGjzMap.get(GjzType.fuSuGjz));

				ngc.setCurrentTimeFuSuPNum(fsProvider.size());//当期复苏献浆员总人数	

				int currentTimeFuSuCollNum = 0;//当期复苏浆员献浆总量/袋	

				if(fsProvider.size() > 2000){
					int num = fsProvider.size() / 2000 + 1;
					for(int j=0;j < num;j++){
						int toIndex = 2000 * j + 2000;
						if(toIndex > fsProvider.size()){
							toIndex = fsProvider.size();
						}
						List<String> subList = fsProvider.subList(2000 * j, toIndex);

						//当期复苏浆员献浆总量/袋	
						DataSourceContextHolder.setDataSourceType(DataSourceConst.jingying);
						int fsCollNum = villageColligateMapper.getCollNumsByProviders(MapUtils.getCurrentYear()+"-01-01",MapUtils.getNowOnlyDateFomat1(),subList);
						currentTimeFuSuCollNum += fsCollNum;
					}

				}else{
					//当期复苏浆员献浆总量/袋	
					DataSourceContextHolder.setDataSourceType(DataSourceConst.jingying);
					if(fsProvider.size()>0){
						currentTimeFuSuCollNum = villageColligateMapper.getCollNumsByProviders(MapUtils.getCurrentYear()+"-01-01",MapUtils.getNowOnlyDateFomat1(),fsProvider);
					}
				}

				ngc.setCurrentTimeFuSuCollNum(currentTimeFuSuCollNum);
				
				int currentTimeZCPNum = 0;//忠诚献浆员当期总人数	
				int currentTimeZCCollNum = 0;//忠诚献浆员当期献浆总量	
				int lastTimeZCPNum = 0;//忠诚献浆员同期期总人数	
				int lastTimeZCCollNum = 0;//忠诚献浆员同期献浆总量	

				int lastYearZCCollNum = 0;//忠诚浆员去年全年献浆量	


				
					
					DataSourceContextHolder.setDataSourceType(DataSourceConst.jingying);
					//忠诚献浆员当期总人数	、忠诚献浆员当期献浆总量	
					Map<String, Integer> tempMaps = villageColligateMapper.getZCAllNums(MapUtils.getThatYear(MapUtils.getCurrentYear(), -1),MapUtils.getCurrentYear(),MapUtils.getNowOnlyDateFomat1(),allProvider);
					currentTimeZCPNum = tempMaps.get("NUM");
					currentTimeZCCollNum = tempMaps.get("SUMNUM");

					//忠诚献浆员同期总人数	、忠诚献浆员同期献浆总量	
					tempMaps = villageColligateMapper.getZCAllNums(MapUtils.getThatYear(MapUtils.getCurrentYear(), -2),MapUtils.getThatYear(MapUtils.getCurrentYear(), -1),MapUtils.getLastYearNow(),allProvider);
					lastTimeZCPNum = tempMaps.get("NUM");
					lastTimeZCCollNum = tempMaps.get("SUMNUM");

					//忠诚献浆员去年全年献浆总量	
					tempMaps = villageColligateMapper.getZCLastYearCOllNums(MapUtils.getThatYear(MapUtils.getCurrentYear(), -1),MapUtils.getCurrentYear(),MapUtils.getNowOnlyDateFomat1(),allProvider);
					lastYearZCCollNum = tempMaps.get("SUMNUM");

				

				ngc.setCurrentTimeZCPNum(currentTimeZCPNum);
				ngc.setCurrentTimeZCCollNum(currentTimeZCCollNum);
				ngc.setLastTimeZCPNum(lastTimeZCPNum);
				ngc.setLastTimeZCCollNum(lastTimeZCCollNum);
				ngc.setLastYearZCCollNum(lastYearZCCollNum);



				int comedNotConnPNum = 0;//进站但未被链接的浆员	
				int comedNotConnThisTimeCollNum = 0;//进站未链接浆员当期献浆量	
				int comedNotConnLastTimeCollNum = 0;//进站未链接浆员同期献浆量	
				int comedNotConnLastYearCollNum = 0;//进站未链接浆员去年献浆总量

				//本村今年进站的浆员
				List<String> comedProvider = MapUtils.retainList(allProvider, MapUtils.allTypeGjzMap.get(GjzType.thisYearComed));
				if(comedProvider.size()>0){
					DataSourceContextHolder.setDataSourceType(DataSourceConst.mx);

					//获取指定浆员中，未被链接的浆员
					List<String> notConnNums = villageColligateMapper.getNotConnProviders(comedProvider);
					comedNotConnPNum = notConnNums.size();
					if(notConnNums.size() > 0){
						DataSourceContextHolder.setDataSourceType(DataSourceConst.jingying);
						comedNotConnThisTimeCollNum = villageColligateMapper.getCollNumsByProviders(MapUtils.getCurrentYear() + "-01-01", MapUtils.getNowOnlyDateFomat1(), notConnNums);
						comedNotConnLastTimeCollNum = villageColligateMapper.getCollNumsByProviders(MapUtils.getThatYear(MapUtils.getCurrentYear(), -1) + "-01-01", MapUtils.getLastYearNow(), notConnNums);
						comedNotConnLastYearCollNum = villageColligateMapper.getCollNumsByProviders(MapUtils.getThatYear(MapUtils.getCurrentYear(), -1) + "-01-01", MapUtils.getThatYear(MapUtils.getCurrentYear(), -1) + "-12-31", notConnNums);
					}
				}
				ngc.setComedNotConnPNum(comedNotConnPNum);
				ngc.setComedNotConnThisTimeCollNum(comedNotConnThisTimeCollNum);
				ngc.setComedNotConnLastTimeCollNum(comedNotConnLastTimeCollNum);
				ngc.setComedNotConnLastYearCollNum(comedNotConnLastYearCollNum);

				DataSourceContextHolder.setDataSourceType(DataSourceConst.jingying);
				//				currentTimeNotComedPNum;//当期未进站总人数	
				List<String> notComedProviders = villageColligateMapper.getNotComedProviders(MapUtils.getCurrentYear(), MapUtils.getNowOnlyDateFomat1(), allProvider);
				ngc.setCurrentTimeNotComedPNum(notComedProviders.size());

				//				currentTimeNotComedPLastYearCollNum;//当期未进站总人数去年献浆总量袋	
				if(notComedProviders.size()>0){
					int currentTimeNotComedPLastYearCollNum = villageColligateMapper.getCollNumsByProviders(MapUtils.getThatYear(MapUtils.getCurrentYear(), -1) + "-01-01", MapUtils.getThatYear(MapUtils.getCurrentYear(), -1) + "-12-31", notComedProviders);
					ngc.setCurrentTimeNotComedPLastYearCollNum(currentTimeNotComedPLastYearCollNum);
				}

				//				xiuMianPNum;//休眠浆员总人数	
				List<String> xmProvider = MapUtils.retainList(allProvider, MapUtils.allTypeGjzMap.get(GjzType.xiuMianGjz));
				ngc.setXiuMianPNum(xmProvider.size());

				if(xmProvider.size()>0){
					//			lastYearXiuMianCollNum;//休眠浆员去年献浆总量/袋	
					int lastYearXiuMianCollNum = villageColligateMapper.getCollNumsByProviders(MapUtils.getThatYear(MapUtils.getCurrentYear(), -1) + "-01-01", MapUtils.getThatYear(MapUtils.getCurrentYear(), -1) + "-12-31", xmProvider);
					//			lastTimeXiuMianCollNum;//休眠浆员同期献浆总量/袋	
					int lastTimeXiuMianCollNum = villageColligateMapper.getCollNumsByProviders(MapUtils.getThatYear(MapUtils.getCurrentYear(), -1) + "-01-01", MapUtils.getLastYearNow(), xmProvider);

					ngc.setLastYearXiuMianCollNum(lastYearXiuMianCollNum);
					ngc.setLastTimeXiuMianCollNum(lastTimeXiuMianCollNum);

				}

				//				connXMPNum;//已链接休眠的献浆员	
				List<String> connXMProvider = MapUtils.retainList(allProvider, MapUtils.allTypeGjzMap.get(GjzType.xiuMianBeConnect));
				ngc.setConnXMPNum(connXMProvider.size());
				if(connXMProvider.size()>0){
					//				lastTimeConnXMCollNum;//已链接休眠的献浆员同期献浆总量/袋	
					int lastTimeConnXMCollNum = villageColligateMapper.getCollNumsByProviders(MapUtils.getThatYear(MapUtils.getCurrentYear(), -1) + "-01-01", MapUtils.getLastYearNow(), connXMProvider);
					ngc.setLastTimeConnXMCollNum(lastTimeConnXMCollNum);
				}

				//				notConnXMPNum;//休眠中未链接献浆员	
				List<String> notConnXMProvider = MapUtils.retainList(allProvider, MapUtils.allTypeGjzMap.get(GjzType.xiuMianNotConnect));
				ngc.setNotConnXMPNum(notConnXMProvider.size());
				if(notConnXMProvider.size()>0){
					//				lastTimeNotConnXMCollNum;//休眠中未链接献浆员同期献浆总量/袋	
					int lastTimeNotConnXMCollNum = villageColligateMapper.getCollNumsByProviders(MapUtils.getThatYear(MapUtils.getCurrentYear(), -1) + "-01-01", MapUtils.getLastYearNow(), notConnXMProvider);
					ngc.setLastTimeNotConnXMCollNum(lastTimeNotConnXMCollNum);
				}

				//				liuShiPNum;//流失浆员总人数	
				List<String> lsProvider = MapUtils.retainList(allProvider, MapUtils.allTypeGjzMap.get(GjzType.liuShiGjz));
				ngc.setLiuShiPNum(lsProvider.size());

				DataSourceContextHolder.setDataSourceType(DataSourceConst.mx);
				//				connedPNum;//已链接献浆员总人数	
				int connedPNum = villageColligateMapper.getConnedPNum(allProvider);
				ngc.setConnedPNum(connedPNum);
				//				VolunteerNum;//义工总人数	
				int volunteerNum = villageColligateMapper.getVolunteerNum(allProvider);
				ngc.setVolunteerNum(volunteerNum);
				//				VolunConnGJZNum;//义工管理浆员总人数
				int volunConnGJZNum = villageColligateMapper.getVolunConnGJZNum(allProvider);
				ngc.setVolunConnGJZNum(volunConnGJZNum);
				nurseGjzGoll = lcblfyMapper.getNurseGjzGoll(ngc.getNurseId());


				if(nurseGjzGoll != null && nurseGjzGoll.size()>0){

					if(nurseGjzGoll.get(0) != null){
						ngc.setId(nurseGjzGoll.get(0).getId());
						logger.info("更新护士【"+ngc.getNurseId()+"】链接的所有浆员的综合信息。。。。。。。");
						lcblfyMapper.updateNurseGjzGoll(ngc);
					}else{
						logger.info("保存护士【"+ngc.getNurseId()+"】链接的所有浆员的综合信息。。。。。。。");
						ngc.setId(UUID.randomUUID().toString());
						lcblfyMapper.saveNurseGjzGoll(ngc);
					}


				}else{
					logger.info("保存护士【"+ngc.getNurseId()+"】链接的所有浆员的综合信息。。。。。。。");
					ngc.setId(UUID.randomUUID().toString());
					lcblfyMapper.saveNurseGjzGoll(ngc);
				}
				 

			}
		}




		logger.info("装载所有护士下面链接的浆员的综合统计信息到数据库 结束。。。。。。。");
		return nurseGjzGoll;
	}


	@Override
	public void loadGjzRoundData(String providerNo) {
		ProviderBaseInfo providerBaseInfo = new ProviderBaseInfo();
		if(providerNo != null && !"".equals(providerNo)){
			logger.info("重新加载供浆者【"+providerNo+"】的轮次信息【只有轮次，没有其他综合统计信息】");
			providerBaseInfo.setProviderNo(providerNo);
		}else{
			logger.info("重新加载所有除开废弃浆员的供浆者的轮次信息【只有轮次，没有其他综合统计信息】");
		}
		DataSourceContextHolder.setDataSourceType(DataSourceConst.jingying);
		List<ProviderBaseInfo> list = gjzxxMapper.getAllGjzExpFeiQi(providerBaseInfo);
		int i = list.size();
		for (ProviderBaseInfo baseInfo : list) {
			providerNo = baseInfo.getProviderNo();
			DataSourceContextHolder.setDataSourceType(DataSourceConst.mx);

			GjzLc gjzLc = gjzLcMapper.getGjzLcByPNo(providerNo);

			if(gjzLc != null){
				setGjzLcData(gjzLc, MapUtils.getCurrentYear(), null, providerNo);
				gjzLcMapper.updateGjzLc(gjzLc);
				logger.info("更新供浆者【"+providerNo+"】的轮次信息成功【只有轮次，没有其他综合统计信息】");
			}else{
				gjzLc = new GjzLc();
				gjzLc.setId(UUID.randomUUID().toString());
				gjzLc.setName(baseInfo.getName());
				gjzLc.setProviderNo(providerNo);

				setGjzLcData(gjzLc, MapUtils.getCurrentYear(), null, providerNo);

				gjzLcMapper.saveGjzLc(gjzLc);
				logger.info("添加供浆者【"+providerNo+"】的轮次信息成功【只有轮次，没有其他综合统计信息】");
			}
			logger.info("剩余执行条数：【 "+--i+" 】条！！！！！");
		}

	}


	@Override
	public void loadAllVillProviders() {
		logger.info("装载所有地址下面的所有浆员卡号集合【没有除开废弃浆员和超龄浆员】！！！！");
		DataSourceContextHolder.setDataSourceType(DataSourceConst.mx);
		List<String> allVill = lcblfyMapper.getNurseVill(null);
		for (String vill : allVill) {
			List<String> list = gjzxxMapper.getProviderByAddress(vill);
			MapUtils.allVillProvider.put(vill, list);
		}
		logger.info("装载所有地址下面的所有浆员卡号集合【没有除开废弃浆员和超龄浆员】结束   ···！！！！");

	}
	/**
	 * 在GJZ_DZ_JWD中查询到NATIVEPATH和ADDRESS能对应上的，
	 * 能对应上表示在GJZ_DZ_JWD已经分配到最小单位了
	 * 在JZJYDZ表里已经存在该村的地址码表信息了。
	 * @param adress
	 * @param nativpath
	 */
	@Override
	public List<String> loadJzjydz(){
		String adress="";
		String nativePath="";
		List<String> list2=new ArrayList<String>();
		List<String> list3=new ArrayList<String>();
		Map<String,String> map=new HashMap<String,String>();
		DataSourceContextHolder.setDataSourceType(DataSourceConst.mx);
		List<String> list=gjzDzJwdMapper.getAdress();
		for(String str :list){
			map.put("adress", str);
			List<String> adressList=splitAddress(str);
			adress = "%";
			for(String ss : adressList){
				adress += ss+"%";
			}
			map.put("nativpath", adress);
			list2=gjzDzJwdMapper.getGjzDzjwdProviderNo(map);
			list3.addAll(list2);
			map.clear();

		}
		return  list3;
	}
	/**
	 * 获取所有的身份证地址集合
	 */
	public List<String> getAlladress(){
		List<String>providerNoList=new ArrayList<String>();
		DataSourceContextHolder.setDataSourceType(DataSourceConst.mx);
		List<GjzDzJwd> list=gjzDzJwdMapper.getGjzDzjwdAdress();
		System.out.println("====================总共有浆员："+list.size());
		for(GjzDzJwd jwd :list){
			if(jwd.getID()!=null){
				providerNoList.add(jwd.getPROVIDERNO());
			}
		}
		return providerNoList;
	}
	/**
	 * 
	 * @param list  身份证地址集合
	 */
	@Override
	public  void  addJzjydz(List<String> list){
		//  str代表地址，解析每个地址信息，再添加到jzjydz表
		Map<String,String> map=new HashMap<String, String>();
		for(String str :list){
			//拆分每一个地址成集合:甘肃省定西市岷县麻子川上沟村  拆分后结果集合：[甘肃省, 定西市, 岷县, 麻子川上沟村]
			List<String>listName=splitAddress(str);
			String path="%";
			for(int i=0;i<listName.size()-1;i++){
				path += listName.get(i)+"%";
				//在这里加方法
				DataSourceContextHolder.setDataSourceType(DataSourceConst.mx);
				map.put("path",path);
				map.put("name", listName.get(i));
				List<JzJyDz>idList=jzjydzMapper.getJzjydzName(map);
				map.clear();
				if(idList.size()>0){
					JzJyDz jzJyDz=idList.get(0); 
					String fuji=jzJyDz.getPATH();
					String newpath="";
					if(fuji.endsWith(".")){
						newpath="%"+fuji.replace(".","%")+listName.get(i+1);
					}else{
						newpath="%"+fuji.replace(".","%")+"%"+listName.get(i+1);
					}

					String parentPath=String.valueOf(jzJyDz.getID());
					show(newpath,parentPath);
				}else{
					//插入省
					show(path, null);
					DataSourceContextHolder.setDataSourceType(DataSourceConst.mx);
					map.put("path",path);
					map.put("name",path.replace("%",""));
					List<JzJyDz>List=jzjydzMapper.getJzjydzName(map);
					map.clear();
					if(List.size()>0){
						JzJyDz jzJyDz=List.get(0); 
						String fuji=jzJyDz.getPATH();
						String newpath="";
						if(fuji.endsWith(".")){
							newpath="%"+fuji.replace(".","%")+listName.get(i+1);
						}else{
							newpath="%"+fuji.replace(".","%")+"%"+listName.get(i+1);
						}

						String parentPath=String.valueOf(jzJyDz.getID());
						show(newpath,parentPath);
					}
				}
			}		
		}
	}
	/**
	 * 保存JZJYDZ信息
	 * @param path  
	 * @param parent  父级的ID
	 */
	public  void show(String path,String parent){
		Map<String,String> paramMap=new HashMap<String, String>();
		DataSourceContextHolder.setDataSourceType(DataSourceConst.mx);
		String cunname="";
		if(parent==null){
			cunname=path.replace("%","");
		}else{
			int lastIndex=path.lastIndexOf("%");
			cunname=path.substring(lastIndex+1);
		}
		paramMap.put("path",path);
		paramMap.put("name",cunname);
		List<JzJyDz>idList=jzjydzMapper.getJzjydzName(paramMap);
		paramMap.clear();
		if(idList.size()>0){

		}else{
			JzJyDz jy=new JzJyDz();
			String gennamePath=path.substring(path.indexOf("%")+1);   
			int last=path.lastIndexOf("%");
			String name=path.substring(last+1);
			//jy.setID(id);  //ID为自增长的
			jy.setCODE("622429");
			if(parent==null){
				jy.setNAME(path.substring(1, path.lastIndexOf("%")));
			}else{
				jy.setNAME(name);
			}

			jy.setPARENTID(parent);
			jy.setPATH(gennamePath.replace("%","."));
			jy.setGEONAME(gennamePath.replace("%",""));
			JzJyDz jzJyDz=getjwd(gennamePath.replace("%",""));
			if(jzJyDz !=null){
				String  gx=jzJyDz.getGX();
				String  gy=jzJyDz.getGY();
				//String dzTypeId=getjwd(gennamePath.replace("%","")).getDZTYPEID();
				jy.setGX(gx);
				jy.setGY(gy);
				//jy.setDZTYPEID(dzTypeId);
			}else{
				logger.error("获取不到取地址【"+gennamePath.replace("%","")+"】的地理信息：");
			}

			DataSourceContextHolder.setDataSourceType(DataSourceConst.mx);
			jzjydzMapper.addJzjydz(jy);
		}

	}
	/**
	 * 根据具体地址从百度API获取经纬度
	 * @param adress
	 * @return
	 * @throws UnsupportedEncodingException 
	 */
	public static JzJyDz getjwd(String patemer) {
		DefaultHttpClient httpclient = new DefaultHttpClient();
		JzJyDz jwdz=null;
		// 创建httpget  
		//String url="http://api.map.baidu.com/geocoder?output=json&address="+patemer;  //百度接口
		try {
			patemer=java.net.URLEncoder.encode(patemer,"utf-8");
		} catch (Exception e) {
			logger.error("发生转码异常");
		}

		String url="http://apis.map.qq.com/ws/geocoder/v1/?key=QWMBZ-E4VC6-JMVSB-MVKIP-HKYX2-VBFGQ&address="+patemer;
		HttpGet httpget = new  HttpGet(url);   
		try {   
			HttpResponse response = httpclient.execute(httpget);   
			try {   
				HttpEntity entity = response.getEntity();
				if (entity != null) {  
					String message = EntityUtils.toString(entity, "utf-8");  
					try{
						JSONObject jsonObject = JSONObject.fromObject(message);
						int total = jsonObject.getInt("status");
						if (total==0) { 
							jwdz=new JzJyDz();
							JSONObject results = jsonObject.getJSONObject("result");  
							//	                         String type= (String) results.get("level");
							//	                         if("省".equals(type)){
							//	                        	 jwdz.setDZTYPEID("2");
							//	                         }else if("城市".equals(type)){
							//	                        	 jwdz.setDZTYPEID("3");
							//	                         }else if("区县".equals(type)){
							//	                        	 jwdz.setDZTYPEID("4");
							//	                         }else if("乡镇".equals(type)){
							//	                        	 jwdz.setDZTYPEID("5");
							//	                         }else if("村庄".equals(type)){
							//	                        	 jwdz.setDZTYPEID("6");
							//	                         }
							JSONObject gson= (JSONObject) results.get("location");
							double lng = (Double) gson.get("lng");
							double lat =(Double) gson.get("lat");
							Double dou_lng = new Double(lng);
							Double dou_lat = new Double(lat);
							NumberFormat nf = NumberFormat.getInstance();
							nf.setGroupingUsed(false);
							String str_lng= nf.format(dou_lng);
							String str_lat= nf.format(dou_lat);
							jwdz.setGX(str_lat);
							jwdz.setGY(str_lng);
							return jwdz;
						}
					}catch (Exception e) {
						logger.error("********="+e.getMessage()+"*********");

					} 
				}   
			} catch (IOException e) {   
				e.printStackTrace();   
			}  
		}catch (IOException e) {   
			e.printStackTrace();   
		} 
		return jwdz;
	}

	public List<String>  loadAddress(){
		List<String> list=new ArrayList<String>();
		ProviderBaseInfo pbif = new ProviderBaseInfo();
		pbif.setFileDate(null);
		DataSourceContextHolder.setDataSourceType(DataSourceConst.jingying);
		List<ProviderBaseInfo> gjzList = gjzxxMapper.getAllProviderBaseInfo(pbif);
		logger.info("待装载的供浆者经纬度数据的供浆者条数："+gjzList.size());
		for(ProviderBaseInfo ss:gjzList){
			list.add(ss.getAddress());
		}
		//return jzjydzMapper.getGeonames();
		return list;
	}
}
